package search;


import java.sql.ResultSet;
import java.sql.SQLException;
import mapapp.ConnectToDatabase;




/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Cookie
 */
public class TraseuInfo {
    String IDfrom;
    String IDto;
    double distance;
    boolean skip;
    java.sql.PreparedStatement statement1;
    java.sql.PreparedStatement statement2;
    ResultSet result1;
    ResultSet result2;
    ConnectToDatabase connection = new ConnectToDatabase();

    TraseuInfo(String f,String t){
        IDfrom=f;
        IDto=t;
        double latF = 0,longF = 0;
        double latT = 0,longT = 0;
        try {
            statement1 = connection.getConnection().prepareStatement("SELECT * FROM `toatestatiile` WHERE `id_statie` LIKE "+f+"");
            statement2 = connection.getConnection().prepareStatement("SELECT * FROM `toatestatiile` WHERE `id_statie` LIKE "+t+"");
            result1 = statement1.executeQuery();
            result2 = statement2.executeQuery();
            while (result1.next()) {
              latF=Double.parseDouble(result1.getString(3));
              longF=Double.parseDouble(result1.getString(4));
            }
            while (result2.next()) {
              latT=Double.parseDouble(result2.getString(3));
              longT=Double.parseDouble(result2.getString(4));
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }finally
    {
        try
        {
            if (result1  != null)
                result1.close();
            if (result2  != null)
                result2.close();
            if (statement1  != null)
                statement1.close();
            if (statement2  != null)
                statement2.close();
            if (connection  != null)
                connection.close();
        }
        catch (SQLException e)
        {
            // ignore
        }
        }
        Punct pctFrom=new Punct(latF,longF);
        Punct pctTo=new Punct(latT,longT);
        Distanta d=new Distanta(pctFrom,pctTo);
        double dist=d.distanceM();
        distance=dist;
        skip=false;
    }

}
